﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TaleGeneratorModel;

namespace Inference
{
    public partial class SelectCharacters : Form
    {
        private TaleClasses _tale_context;
        private List<string> _characters_names;
        public bool success;
        public List<long> IDCharacters;
        
     
        public SelectCharacters()
        {
            InitializeComponent();           
        }


        public SelectCharacters(TaleClasses TaleContext)
        {
            InitializeComponent();
            _tale_context = TaleContext;
            _characters_names = new List<string>();
            IDCharacters = new List<long>();
            // initizialiation tree

        }


        private void SelectCharacters_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Вы уверены, что хотите выйти?", "", MessageBoxButtons.YesNo,
             MessageBoxIcon.None, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                success = false;
            }
            else
                e.Cancel = true;
        }


        private void BtnOK_Click(object sender, EventArgs e)
        {
            success = true;
            this.Close();
        }


        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void BtnAddCharacter_Click(object sender, EventArgs e)
        {
            string character_name = TxtCharacterName.Text.Trim();
            if (character_name.Length > 0)
            {
                if (!_characters_names.Contains(character_name)) // !!!
                {
                    IDCharacters.Add((long)TreeCharacters.SelectedNode.Tag);
                    DgvCharacters.Rows.Add(1);
                    DgvCharacters.Rows[DgvCharacters.RowCount - 1].Cells[0].Value = character_name;
                    DgvCharacters.Rows[DgvCharacters.RowCount - 1].Cells[1].Value = TreeCharacters.SelectedNode.Text;
                }
                else
                    MessageBox.Show("Герой с данным именем уже есть");
            }
            else
                MessageBox.Show("Введите что-то");
        }


        private void BtnDelete_Click(object sender, EventArgs e)
        {
            IDCharacters.RemoveAt(DgvCharacters.CurrentRow.Index);
            _characters_names.Remove((string)DgvCharacters.CurrentRow.Cells[0].Value);
            DgvCharacters.Rows.Remove(DgvCharacters.CurrentRow);
        }

    }
}